	import flash.geom.Point;

	class ScreenCoordsRadar extends ScreenCoordsBase
	{
		 inline static var TO_RADIANS: Float = Math.PI / 180;
		 var range:Range;
		 var angles: Int;
		 var angle: Float;
		 var radius: Float;
		
		public function new( top: Float, left: Float, right: Float, bottom: Float ) {
			super(top, left, right, bottom);
			//
			// if the radar chart has labels this is going to
			// get updated so they fit onto the screen
			//
			this.radius = ( Math.min( this.width, this.height ) / 2.0 );
		}
		
		// axis range, from center to outer edge
		public function set_range( r:Range ): Void {
			this.range = r;
		}
		
		public function get_max(): Float {
			return this.range.max;
		}
		
		// how many axis/spokes
		public function set_angles( a: Float ):Void {
			this.angles = Std.int(a);
			this.angle = 360 / a;
		}
		
		public function get_angles(): Int {
			return this.angles;
		}
		
		public function get_radius(): Float {
			
			return this.radius;
		}
		
		public function reduce_radius():Void {
			this.radius--;
		}
		
		public function get_pos( angle: Float, radius: Float ): flash.geom.Point {
			
			// flash assumes 0 degrees is horizontal to the right
			var a: Float = (angle - 90) * TO_RADIANS;
			var r: Float = this.get_radius() * radius;
			
			var p:flash.geom.Point = new flash.geom.Point(
				r * Math.cos(a),
				r * Math.sin(a) );
				
			return p;
		}
		
		public override function get_get_x_from_pos_and_y_from_val( index: Float, y: Float, right_axis:Bool = false ):flash.geom.Point {
			
			// rotate
			var p:flash.geom.Point = this.get_pos( this.angle*index, y / this.range.count() );
			
			// translate
			p.x += this.get_center_x();
			p.y += this.get_center_y();
			
			return p;
		}
		
		public override function get_y_from_val( y: Float, right_axis:Bool = false ): Float {
			
			// rotate
			var p:flash.geom.Point = this.get_pos( 0, y / this.range.count() );
			
			// translate
			p.y += this.get_center_y();
			
			return p.y;
		}
	}
